const express = require('express');
const mysql = require('mysql2');
const app = express();
const port = 1234;
const connection = mysql.createConnection({host: 'localhost',user: 'root',password: '123456',database: 'film'});

app.get('/bookauthor/:bookname', (req, res) => {
    const sql = 'select authorName from xiaoshuo where bookName = ?';
    connection.query(sql, [req.params.bookname], (err, results) => {
        if (err) {return console.error('query error:', err.message);}
        res.send(`${req.params.bookname}的作者：${results[0].authorName}`);
    });
});
app.listen(port, () => console.log(`Example app listening on port ${port}!`));

// app.get('/filmpiaofang/:filmname', (req, res) => {
//     const sql = 'select money from piaofang where filmname = ?';
//     connection.query(sql, [req.params.filmname], (err, results) => {
//         if (err) {return console.error('query error:', err.message);}
//         res.send(`${req.params.filmname}的票房：${results[0].money}`);
//     });
// });

// app.get('/filmtime/:filmname', (req, res) => {
//     const sql = 'select time from piaofang where filmname = ?';
//     connection.query(sql, [req.params.filmname], (err, results) => {
//         if (err) {return console.error('query error:', err.message);}
//         res.send(`${req.params.filmname}的上映时间：${results[0].time}`);
//     });
// });

// app.get('/filmcount/:filmname', (req, res) => {
//     const sql = 'select count from piaofang where filmname = ?';
//     connection.query(sql, [req.params.filmname], (err, results) => {
//         if (err) {return console.error('query error:', err.message);}
//         res.send(`${req.params.filmname}的观影人数：${results[0].count}`);
//     });
// });


